<?php

namespace App\Http\Middleware;

use App\Exceptions\BaseException;
use App\Kuafu\Base\Enum\BaseCodeEnum;
use App\Kuafu\Common\Enum\CodeEnum;
use App\Kuafu\User\Model\Permissions;
use App\Kuafu\User\Model\RolePermissionMappings;
use App\Kuafu\User\Model\UserRoleMapping;
use App\Kuafu\User\Service\AuthService;
use App\Kuafu\User\Service\PermissionsService;
use App\Kuafu\User\Service\UserRoleService;
use Closure;
use Illuminate\Http\Request;


class MerchantUserPermission
{
    /**
     * Check Permission
     *
     * @param \Illuminate\Http\Request $request
     * @param \Closure $next
     * @param string|null ...$guards
     * @return mixed
     */
    public function handle(Request $request, Closure $next)
    {
        if (config('app.env') == 'dev') {
            return $next($request);
        }

        $userInfo = AuthService::getAuthUser();
        if ($userInfo->status == \App\Kuafu\User\Enum\CodeEnum::USER_STATUS_STOP) {
            throw new BaseException(BaseCodeEnum::ERR_ACCOUNT_BANNED);
        }

        return $next($request);
    }
}
